package com.manda.smart.hub.common.concurrent;

import java.util.StringJoiner;

/**
 * 带有身份标识的 ThreadLocal
 * 身份标识可以是 Name、ID 等
 *
 * @author hongda.li
 */
public class IdentityThreadLocal<Identity, T> extends ThreadLocal<T> {
    /**
     * 身份标识标记
     */
    private final Identity identity;

    public IdentityThreadLocal(Identity identity) {
        this.identity = identity;
    }

    public Identity getIdentity() {
        return identity;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", IdentityThreadLocal.class.getSimpleName() + "[", "]")
                .add("identity=" + identity)
                .toString();
    }
}
